package org.pine.start;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;

/**
 * 启动类
 *
 * @author pine
 * @version 1.0
 * @since 2025-04-10 15:41
 */
@Slf4j
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableCaching
@MapperScan("org.pine.model.mapper")
@EnableConfigurationProperties
@ConfigurationPropertiesScan
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"org.pine"})
public class PineStartApplication {

    public static void main(String[] args) {
        try {
            SpringApplication app = new SpringApplication(PineStartApplication.class);
            app.setBannerMode(Banner.Mode.LOG);
            ConfigurableApplicationContext applicationContext = app.run(args);
            Environment environment = applicationContext.getEnvironment();
            String protocol = "http";

            String sb = """


                    ----------------------------------------------------------------
                    \tApplication '{}' is running! Access URLs:
                    \tLocal:\t\t{}://localhost:{}/pine
                    \tExternal:\t{}://{}:{}/pine
                    \tProfile(s):\t{}
                    \tOpenAPI:\t{}://{}:{}/pine/doc.html
                    ----------------------------------------------------------------
                    """;
            log.info(sb,
                    environment.getProperty("spring.application.name")
                    , protocol, environment.getProperty("server.port")
                    , protocol, InetAddress.getLocalHost().getHostAddress(), environment.getProperty("server.port")
                    , environment.getActiveProfiles()
                    , protocol, InetAddress.getLocalHost().getHostAddress(), environment.getProperty("server.port")
            );
        } catch (Exception exception) {
            log.error("SpringApplication run failed", exception);
        }
    }
}
